package com.ly.hotel.spainterface.jyt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.ly.hotel.R;
import com.ly.hotel.spainterface.jyt.bean.consume.ConsumeBean;

import java.util.List;

/**
 * Created by ThinkPad on 2018/3/19.
 */

public class ConsumeCategoryAdapter extends BaseAdapter{

    private Context context;
    private List<ConsumeBean> consumeBeans;
    private int defaultPosition = 0;
    // 设置默认选中项
    public void setDefaultPosition(int defaultPosition) {
        this.defaultPosition = defaultPosition;
        notifyDataSetChanged();
    }

    public ConsumeCategoryAdapter(Context context, List<ConsumeBean> consumeBeans){
        this.context = context;
        this.consumeBeans = consumeBeans;
    }

    @Override
    public int getCount() {
        return consumeBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return consumeBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if(convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.jyt_consume_category_item,null);
            viewHolder = new ViewHolder();
            viewHolder.consumeCategoryName = view.findViewById(R.id.consume_category_name);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        if(defaultPosition == position){
            //view.setBackgroundResource(R.color.itemSelect);
            viewHolder.consumeCategoryName.setTextColor(ContextCompat.getColor(context,R.color.itemName));
        }else{
            viewHolder.consumeCategoryName.setTextColor(ContextCompat.getColor(context,R.color.mainWhite));
            //view.setBackgroundResource(android.R.color.transparent);
        }
        ConsumeBean consumeBean = consumeBeans.get(position);
        viewHolder.consumeCategoryName.setText(consumeBean.getName());
        return view;
    }

    class ViewHolder{
        TextView consumeCategoryName;
    }
}
